package vn.sunnet.backviet01.game.coloa.animated.skill;

import org.anddev.andengine.entity.sprite.BaseSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import vn.sunnet.backviet01.game.coloa.constant.Constants;

public class SkillBangHa extends AnimatedSkill{
	
	private static final long[] duration = {100, 100, 100, 100, 600, 100, 100, 100, 100, 100};
	
	private boolean isDestroy = false;
	
	private boolean isTrans = false;
	private boolean isAttak = false;
	private boolean isCheck = false;
	
	private long coolDownEnemy = 0;
	
	private float damage = 0;
	private float useMana = 0;
	
	private final int name;
	private long start = 0;
	
	public SkillBangHa(int name, float pX, float pY,
			TiledTextureRegion pTiledTextureRegion) {
		super(name, pX, pY, pTiledTextureRegion);
		setPosition(pX - 90, pY - 70);
		animate(duration);
		this.name = Constants.SKILL_BANG_HA;
		start = System.currentTimeMillis();
	}
	
	public void onManagedUpdate(float pSecondsElapsed) {
		if (this.getCurrentTileIndex() > 2 && this.getCurrentTileIndex() < 7 ) {
			if (!isCheck) {
				isAttak = true;
				isCheck = true;
			}
		} 
		else if (this.getCurrentTileIndex() == 9) {
			if (this.getAlpha() > 0.05)
				this.setAlpha(getAlpha() - 0.005f);
			if (!isTrans) {
				isTrans = true;
				this.setZIndex(0);
			}
		}
		
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	@Override
	public boolean attack(final float pX, final float pY) {
		float xOffset = this.xGoal - pX;
		float yOffset = this.yGoal - pY;
		
		float offset = (float)(Math.sqrt(xOffset * xOffset + yOffset * yOffset));
		
		if (offset < 100 + mLevel * 7)
			return true;
		
		return false;
	}

	public void setDestroy(boolean pDestroy) {
		this.isDestroy = pDestroy;
	}
	
	public boolean isDestroy() {
		return isDestroy;
	}
	
	@Override
	public void complete() {
		
	}

	@Override
	public int getName() {
		return name;
	}

	@Override
	public boolean isAttack() {
		return isAttak;
	}

	@Override
	public void stopInfluence() {
		isAttak = false;
	}
	@Override
	public float getDamge() {
		return damage;
	}

	@Override
	public void setDamage(float damage) {
		this.damage = damage;
	}

	@Override
	public float useMana() {
		return useMana;
	}

	@Override
	public void setMana(float mana) {
		this.useMana = mana;
	}
	@Override
	public long getStart() {
		return start;
	}

	@Override
	public void remove() {
		
	}

	@Override
	public BaseSprite returnSeft() {
		return this;
	}


	@Override
	public long getCoolDownEnemy() {
		return coolDownEnemy;
	}

	@Override
	public void setCoolDownEnemy(long coolDown) {
		this.coolDownEnemy = coolDown;
		
	}
	
}
